﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Windows;
using System.Threading;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Data.Services.Client;
using System.IO.IsolatedStorage;
using System.IO;
using System.Xml.Linq;
using Infragistics;
using Infragistics.Controls.Schedules;
using Infragistics.Controls.Interactions;
using Infragistics.Controls.Interactions.Primitives;
using Infragistics.Controls.Schedules.Primitives;
using System.Windows.Browser;
using Ivvy_Silverlight.i7SR;
using Ivvy_Silverlight.Ivvy;
using Sqo;
using Sqo.Attributes;


namespace Ivvy_Silverlight
{
    public partial class MainPage : UserControl
    {
        public XamMonthView MonthView;
        public XamDayView DayView;
        public XamScheduleDataManager InitialXamScheduleDataManager;
        public static List<ExtendedGrid> TestExtendedGrid = new List<ExtendedGrid>();
        public static ExtendedScheduleStackPanel TestExtendedScheduleStackPanel;
        public static ExtendedScheduleActivityPanel TestExtendedScheduleActivityPanel;
        public static ExtendedTimeslotPanel TestExtendedTimeslotPanel;
        public static DataManipulations DataManager;        
        private bool NeedSetSelectedTimeRange = true;
        public string Global_StoreKey = string.Empty;

        public static ClientData Global_Store = new ClientData();
        public ClientData Global_Store_test = new ClientData();
        private SaveLoad _SaveLoad = new SaveLoad();

        public MainPage()
        {   InitializeComponent();
            FillInitialData();
            DynamicCreateControls();
            SetLoadSaveControlsVisibility(true);
        }

        private void DynamicCreateControls()
        {
            DynamicCreateMonthView();
            DynamicCreateDayView();
            MonthView.LayoutUpdated += new EventHandler(MonthView_LayoutUpdated);
        }

        //int DebugCounter = 0;
        private void MonthView_LayoutUpdated(object sender, EventArgs e)
        {
            
            if (DataManager.VisibleDatesinMonthView.HasValue && MonthView.VisibleDates.Count > 0 &&
                DataManager.Data.vw_Appointment_SummaryC.Count > 0 && NeedSetSelectedTimeRange)
                if (DataManager.VisibleDatesinMonthView.Value.Start != MonthView.VisibleDates.First() ||
                    DataManager.VisibleDatesinMonthView.Value.End != MonthView.VisibleDates.Last())
                {
                    NeedSetSelectedTimeRange = false;
                    DataManager.VisibleDatesinMonthView = new DateRange(MonthView.VisibleDates.First(), MonthView.VisibleDates.Last());
                    DataManager.Loadvw_Appointment_Summary();
                    /*MessageTB.Text = MonthView.VisibleDates.First().ToString() + "  " + MonthView.VisibleDates.Last().ToString() + "   " + 
                                    (DebugCounter++).ToString() + "  " + DataManager.Data.vw_Appointment_SummaryC.Count.ToString();*/
                }
        }

        private void FillInitialData()
        {
            InitialXamScheduleDataManager = CreateInitialXamScheduleDataManager();
            DataManager = new DataManipulations();
        }

        private void Save_Store(DataManipulations DataManager)
        {
            
            Global_Store = DataManager.Data;
            try
            {
                Global_StoreKey = _SaveLoad.Save(Global_Store);
            }
            catch (Exception e)
            {
                string str = e.ToString();
            }
        }
        private void Load_Store(string Global_StoreKey)
        {
            Global_Store_test = _SaveLoad.Load(Global_StoreKey);
        }
        

        private void LoadDataButton_Click(object sender, RoutedEventArgs e)
        {
            SetLoadSaveControlsVisibility(false);
            if (!DataManager.LoadCollectionsCompleted_IsNull())
                DataManager.LoadCollectionsCompleted -= new EventHandler<EventArgs>(LoadCollections_Completed);            
            DataManager.LoadCollectionsCompleted += new EventHandler<EventArgs>(LoadCollections_Completed);
            if (!DataManager.LoadCollectionsProgressCallbak_IsNull())
                DataManager.LoadCollectionsProgressCallbak -= new EventHandler<EventArgs>(LoadCollections_ProgressCallbak);
            DataManager.LoadCollectionsProgressCallbak += new EventHandler<EventArgs>(LoadCollections_ProgressCallbak);
            MonthView.SelectedTimeRange = new DateRange(new DateTime(2009, 2, 15), new DateTime(2009, 2, 16));            
            DataManager.VisibleDatesinMonthView = new DateRange(MonthView.SelectedTimeRange.Value.Start.AddDays(-20),
                                                                MonthView.SelectedTimeRange.Value.Start.AddDays(20));
            DataManager.LoadCollectionsFromOData();
        }

        private void LoadCollections_ProgressCallbak(object sender, EventArgs e)
        {
            if (sender is string)
            {
                Dispatcher.BeginInvoke(() => { MessageTB.Text = (string)sender; });
                if (((string)sender).IndexOf("100") >= 0)
                    Dispatcher.BeginInvoke(() => 
                    { 
                        SetLoadSaveControlsVisibility(true);
                        SaveviaSiaqodbButton_Click(sender, null);
                    });
            }   
        }

        private void LoadCollections_Completed(object sender, EventArgs e)
        {
            BindDataToCalendarControls();
        }

        private void BindDataToCalendarControls()
        {
            DateRange? SelectedDateRange = DataManager.BindDataToScheduleDataManager(InitialXamScheduleDataManager, NeedSetSelectedTimeRange);
            if (NeedSetSelectedTimeRange)
            {
                if (SelectedDateRange != null)
                    MonthView.SelectedTimeRange = SelectedDateRange.Value;
            }
            else 
                NeedSetSelectedTimeRange = true;
            
        }//private void BindDataToCalendarControl()

        private void Test_ISS_Click(object sender, RoutedEventArgs e)
        {
            Save_Store(DataManager);
            Load_Store(Global_StoreKey);
            DataManager.Data = null;
            this.LayoutRoot.Children.Remove(MonthView);
            MonthView = null;
            DynamicCreateMonthView();
       }
        
        private static XamMonthView _MonthView;

        private void Test_ISS_Load_Click(object sender, RoutedEventArgs e)
        {
            DataManager.Data = Global_Store;
            BindDataToCalendarControls();
            _MonthView = MonthView;
            _SaveLoad.AutoSave();
            

        }
        public static string MonthView_Key;
        private void clearstore(object sender, RoutedEventArgs e)
        {
            _SaveLoad.ClearStore();
        }
        private void SaveMonthView(object sender, RoutedEventArgs e)
        {
            MonthView_Key = _SaveLoad.Save(_MonthView);
            _SaveLoad.AutoSave();
            this.LayoutRoot.Children.Remove(MonthView);
            MonthView = null;
            DynamicCreateMonthView();
        }

        private void LoadMonthView(object sender, RoutedEventArgs e)
        {
            MonthView = _SaveLoad.Load_XamMonthView(MonthView_Key);
            BindDataToCalendarControls();
        }


        private void DynamicCreateMonthView()
        {
            MonthView = new XamMonthView() 
                {
                    DataManager = InitialXamScheduleDataManager,
                    Margin = new Thickness(250, 50, 0, 0),
                    Width = 700,
                    Height = 500
                };
            MonthView.MouseLeftButtonUp += new MouseButtonEventHandler(MonthView_MouseLeftButtonUp); 
            MonthView.DayHeaderClick += new EventHandler<ScheduleHeaderClickEventArgs>(MonthView_DayHeaderClick);
            this.LayoutRoot.Children.Add(MonthView);            
        }//private void DynamicCreateMonthView()

        private void MonthView_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            XamMonthView MonthView = sender as XamMonthView;
            if (MonthView.SelectedActivities.Count == 0 && MonthView.SelectedTimeRange.HasValue && e.OriginalSource is Border)
            {
                DateTime StartDT = MonthView.SelectedTimeRange.Value.Start;
                DateTime StartDR = new DateTime(StartDT.Year, StartDT.Month, StartDT.Day);
                DayView.SelectedTimeRange = new DateRange(StartDR, StartDR.AddDays(1));
                MonthDayViewButton_Click(sender, null);                
            }
        }//private void MonthView_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)

        private void MonthView_DayHeaderClick(object sender, ScheduleHeaderClickEventArgs e)
        {
            MonthView.SelectedTimeRange = new DateRange(e.Date, e.Date.AddDays(1));
        }

        private void DynamicCreateDayView()
        {
            DayView = new XamDayView() 
                            {
                                SelectedTimeRange = new DateRange(new DateTime(2009, 2, 17, 18, 0 ,0)),
                                DataManager = InitialXamScheduleDataManager,
                                Margin = new Thickness(250, 50, 0, 0),
                                Width = 700,
                                Height = 500,
                                Visibility = Visibility.Collapsed,
                                TimeslotInterval = new TimeSpan(0, 60, 0)
                            };
            
            this.LayoutRoot.Children.Add(DayView);
        }//private void DynamicCreateMonthView()

        public XamScheduleDataManager CreateInitialXamScheduleDataManager()
        {
            ObservableCollection<Resource> resources = new ObservableCollection<Resource>();
            Resource resAmanda = new Resource() { Id = DataManipulations.DayMonthViewOwningResourceId, Name = DataManipulations.DayMonthViewResourceName };
            resources.Add(resAmanda);
            ObservableCollection<ResourceCalendar> calendars =
                new ObservableCollection<ResourceCalendar>();
            ResourceCalendar calAmanda = new ResourceCalendar()
            {
                Id = DataManipulations.DayMonthViewResourceCalendarId,
                OwningResourceId = DataManipulations.DayMonthViewOwningResourceId
            };
            calendars.Add(calAmanda);

            ObservableCollection<Appointment> appointments = new ObservableCollection<Appointment>();
            ListScheduleDataConnector scheduleDataConnector = new ListScheduleDataConnector();
            scheduleDataConnector.ResourceItemsSource = resources;
            scheduleDataConnector.ResourceCalendarItemsSource = calendars;
            scheduleDataConnector.AppointmentItemsSource = appointments;
            //scheduleDataConnector.TimeZoneInfoProvider = new CustomTimeZoneInfoProvider();


            XamScheduleDataManager scheduleDataManager = new XamScheduleDataManager();
            scheduleDataManager.DialogFactory = new CustomizedAppointmentDialog();
            scheduleDataManager.DataConnector = scheduleDataConnector;
            scheduleDataManager.PromptForLocalTimeZone = PromptForLocalTimeZone.Never;

            string LID = string.Empty;
            foreach (var CurTimeZoneToken in scheduleDataManager.DataConnector.TimeZoneInfoProviderResolved.TimeZoneTokens)
                if (CurTimeZoneToken.DisplayName.IndexOf("(UTC)") != -1)
                {                    
                    scheduleDataConnector.TimeZoneInfoProvider = CurTimeZoneToken.Provider;
                    scheduleDataConnector.TimeZoneInfoProvider.LocalTimeZoneId = CurTimeZoneToken.Id;                
                    break;
                }
            

            CalendarGroupCollection calGroups = scheduleDataManager.CalendarGroups;
            CalendarGroup calGroup = new CalendarGroup();
            calGroup.InitialCalendarIds = DataManipulations.DayMonthViewOwningResourceId + "[" + DataManipulations.DayMonthViewResourceCalendarId + "]";
            calGroups.Add(calGroup);
            return scheduleDataManager;
        }


        private void NewCalendarButton_Click(object sender, RoutedEventArgs e)
        {
         
            CalendarItem NewCI = new CalendarItem() 
                         {   
                             Verb_ID = 2,
                             Entry_ID = 2053,
                             Status_ID = 120,
                             StatusNote = "0",
                             Create_Date = DateTime.Now,
                             Update_Date = DateTime.Now, 
                             Created_User_ID = 1,
                             Salutation = "Mr.",
                             FirstName = "Ivan",
                             MiddleName = string.Empty,
                             LastName = "Rest",
                             Entry_Name = "sobr2", 
                             Start_Date = DateTime.Now, 
                             End_Date = DateTime.Now, 
                             GUID = System.Guid.NewGuid().ToString() };
            DataManager.svc.AddObject("CalendarItems", NewCI);            
            DataManager.svc.BeginSaveChanges(BeginSaveChangesCallback, DataManager.svc);
            //svc.AddObject("CalendarItems", NewCI); 
            //svc.UpdateObject(NewCI);     
            //svc.CalendarItems.BeginExecute(BeginSaveChangesCallback, svc.CalendarItems);
            
            //var t= new DataServiceCollection<CalendarItem>(svc);
            //t.Add(NewCI);

            // svc.BeginSaveChanges(BeginSaveChangesCallback, null);
            
        }

        private void BeginSaveChangesCallback(IAsyncResult result)
        {            
            if(result.AsyncState is i7e)
                ((i7e)result.AsyncState).EndSaveChanges(result);           
        }

        private void SaveToIStorageB_Click(object sender, RoutedEventArgs e)
        {
            if (DataManager.Data.GetTotalCount() > 0)
            {
                DataManager.LoadSaveDataCompletedCallbak += new EventHandler<EventArgs>(SaveData_Completed);
                SetLoadSaveControlsVisibility(false);
                DataManager.SaveToIStorageinXML();
            }
            else
                MessageBox.Show("No data to save", "Error", MessageBoxButton.OK);
        }

        private void SaveData_Completed(object sender, EventArgs e)
        {
            Dispatcher.BeginInvoke(() => { SetLoadSaveControlsVisibility(true); });
            DataManager.LoadSaveDataCompletedCallbak -= new EventHandler<EventArgs>(SaveData_Completed);
        }



        private void LoadFromIsolatedStorageB_Click(object sender, RoutedEventArgs e)
        {
            DataManager.LoadSaveDataCompletedCallbak += new EventHandler<EventArgs>(LoadData_Completed);            
            if (DataManager.LoadFromIStorageinXML())
            {
                SetLoadSaveControlsVisibility(false);
            }
            else
                MessageBox.Show("No data exist in isolated storage", "Error", MessageBoxButton.OK);
        }

        private void LoadData_Completed(object sender, EventArgs e)
        {
            Dispatcher.BeginInvoke(() => 
            { 
                SetLoadSaveControlsVisibility(true);
                DateRange? SelectedDateRange = DataManager.BindDataToScheduleDataManager(InitialXamScheduleDataManager);
                if (SelectedDateRange != null)
                    MonthView.SelectedTimeRange = SelectedDateRange.Value;
            });
            DataManager.LoadSaveDataCompletedCallbak -= new EventHandler<EventArgs>(LoadData_Completed);            
        }

        private void SaveToIStorageinBinaryB_Click(object sender, RoutedEventArgs e)
        {
            if(DataManager.Data.GetTotalCount() > 0)
            {
                DataManager.LoadSaveDataCompletedCallbak += new EventHandler<EventArgs>(SaveData_Completed);
                SetLoadSaveControlsVisibility(false);
                DataManager.SaveToIStorageinBinary();                          
            }
            else
                MessageBox.Show("No data to save", "Error", MessageBoxButton.OK);
        }

        private void LoadFromIsolatedStorageinBinaryB_Click(object sender, RoutedEventArgs e)
        {
            DataManager.LoadSaveDataCompletedCallbak += new EventHandler<EventArgs>(LoadData_Completed);
            if (DataManager.LoadFromIStorageinBinary())
            {
                SetLoadSaveControlsVisibility(false);
            }
            else
                MessageBox.Show("No data exist in isolated storage", "Error", MessageBoxButton.OK);            
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            HideTrialMessage();
        }

        public void HideTrialMessage()
        {        
            foreach (var popup in VisualTreeHelper.GetOpenPopups())        
                if (popup.Child.GetType().Name == "TrialControl")
                    popup.Child.Visibility = System.Windows.Visibility.Collapsed;
        }
       

        private void TestButton_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("test is ok");
            return;

        }

        private void SynchronizeCalendarItemsButton_Click(object sender, RoutedEventArgs e)
        {
            DataManager.SynchronizeCalendarItems();
        }

        private void MonthDayViewButton_Click(object sender, RoutedEventArgs e)
        {
            MonthView.Visibility = MonthView.Visibility == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
            DayView.Visibility = MonthView.Visibility == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
            MonthDayViewButton.Content =  MonthView.Visibility == Visibility.Visible ? "Switch to day view" : "Switch to month view";
        }

        public void SetLoadSaveControlsVisibility(bool IsVisible)
        {
            Visibility NewVisibility = IsVisible ? Visibility.Visible : Visibility.Collapsed;
            LoadDataButton.Visibility = NewVisibility;
            //NewCalendarButton.Visibility = NewVisibility;
            SaveviaSiaqodbButton.Visibility = NewVisibility;
            LoadviaSiaqodbButton.Visibility = NewVisibility;
            SaveToIStorageinXMLB.Visibility = NewVisibility;
            LoadFromIsolatedStorageinXMLB.Visibility = NewVisibility;
            SaveToIStorageinBinaryB.Visibility = NewVisibility;
            LoadFromIsolatedStorageinBinaryB.Visibility = NewVisibility;
            DeleteIsolatedStorageFilesButton.Visibility = NewVisibility;
            SynchronizeCalendarItemsButton.Visibility = NewVisibility;
        }//public void SetLoadSaveControlsVisibility(bool IsVisible)

        private void button1_Click(object sender, RoutedEventArgs e)
        {

        }

        private void DeleteIsolatedStorageFilesButton_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("Do you really want to delete all files in isolated storage?", "Question", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                DataManager.DeleteAllFilesInIsolatedStorage();
        }
                

        private void TestTestButton_Click(object sender, RoutedEventArgs e)
        {
            string ss = String.Empty;

            int NewHeight = 20;

            int i = 0;
            foreach (var CurGrid in TestExtendedGrid)
            {
                //if (i++ == 10)
                {
                    CurGrid.Height = NewHeight;
                    foreach (var CurChild in CurGrid.Children)
                        if(CurChild is Border)
                            (CurChild as Border).Height = NewHeight;
                    CurGrid.Children.Add(new TextBlock { Text = (i++).ToString()});
                }

            }
            i = 0;
            double HeightOffset = 0;
            double[] Heights = new double[24];
            if (TestExtendedTimeslotPanel != null)
            foreach (var CurChild in TestExtendedTimeslotPanel.Children)
            {
                ss += CurChild.ToString();
                
                
                if (CurChild is TimeslotPresenter)
                {
                    TimeslotPresenter CTimeslotPresenter = CurChild as TimeslotPresenter;
                    CTimeslotPresenter.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                    CTimeslotPresenter.UseLayoutRounding = false;                    
                    HeightOffset += CTimeslotPresenter.ActualHeight - NewHeight;
                    CTimeslotPresenter.Height = NewHeight;

                    //if (i++ == 10)
                    CTimeslotPresenter.Margin = new Thickness(0, -HeightOffset, 0, 0);
                    Heights[i++] = HeightOffset;   
                    
                }
                else ss = "ethe";
            }

            HeightOffset = 0;
            foreach (var CurChild in TestExtendedScheduleActivityPanel.Children)
            {   
                ss += CurChild.ToString();
                if (CurChild is AppointmentPresenter)
                    if ((CurChild as AppointmentPresenter).Activity != null)
                {
                    AppointmentPresenter CAppointmentPresenter = CurChild as AppointmentPresenter;
                    HeightOffset += CAppointmentPresenter.ActualHeight - NewHeight;
                    CAppointmentPresenter.Height = NewHeight;
                    CAppointmentPresenter.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                    CAppointmentPresenter.UseLayoutRounding = false;
                    CAppointmentPresenter.Margin = new Thickness(0, -Heights[CAppointmentPresenter.Activity.Start.Hour], 0, 0);
                    
                }
                else ss = "ethe";
            }
        }

        
        private void ExportToWordButton_Click(object sender, RoutedEventArgs e)
        {
            ExportToWord ExportToWordC = new ExportToWord();
            if(DataManager.Data.CalendarItemsC.Count >=2)
            if (!ExportToWordC.ExportToWord_CalendarItem(DataManager.Data.CalendarItemsC[1]))
                MessageBox.Show("This application can't save to word document.\n Please contact you system administrator");
            
        }

        private void CloseApplicationButton_Click(object sender, RoutedEventArgs e)
        {
            
            if (Application.Current.IsRunningOutOfBrowser && Application.Current.HasElevatedPermissions)
                Application.Current.MainWindow.Close();
        }

        private void TestISSButton_Click(object sender, RoutedEventArgs e)
        {            
            List<ClientData> BigData = new List<ClientData>();
            for (int i = 0; i < 3; i++)
                BigData.Add( DataManager.Data);

                IsolatedStorageSettings.ApplicationSettings.Add("testkey", BigData);
                IsolatedStorageSettings.ApplicationSettings.Save();
        }

        private void TestISSLoadButton_Click(object sender, RoutedEventArgs e)
        {
            List<ClientData> BigData = new List<ClientData>();
            if (IsolatedStorageSettings.ApplicationSettings.Contains("testkey"))
                BigData = (List<ClientData>)IsolatedStorageSettings.ApplicationSettings["testkey"];
        }

        
        private void TestReccurenceButton_Click(object sender, RoutedEventArgs e)
        {

            ObservableCollection<i_CalendarItem> NewCalItem = new ObservableCollection<i_CalendarItem>();
                        
            var query = from i_CalendarItem ci in DataManager.siaqodb
                        where ci.FirstName.IndexOf("Jim") != -1
                        select ci;
            foreach (var CurItem in query)
                NewCalItem.Add(CurItem);


            ObservableCollection<i_CalendarItem_Field> NewCal_FieldItem = new ObservableCollection<i_CalendarItem_Field>();

            int SearchCalendarItem_ID = 225675;
            var query2 = from i_CalendarItem_Field cal in DataManager.siaqodb
                        where cal.CalendarItem_ID == SearchCalendarItem_ID
                        select cal;
            foreach (var CurItem in query2)
               NewCal_FieldItem.Add(CurItem);

            /*var MetaTypeSiaqodb = DataManager.siaqodb.GetAllTypes();
            List<int> AllOIDs = DataManager.siaqodb.LoadAllOIDs(MetaTypeSiaqodb[12]);*/

        }
        private void NotesAdmin_Click(object sender, RoutedEventArgs e)
        {
            ChildWindow NotesAdmin = new Activitywindow();
            NotesAdmin.Show();
        }

        private void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            if (DataManager.Data.GetTotalCount() > 0)
            {
                ChildWindow sw = new Search2();
                sw.Show();
            }
            else
                MessageBox.Show("Please load data first", "No data to search", MessageBoxButton.OK);
            
        }

        private void SaveviaSiaqodbButton_Click(object sender, RoutedEventArgs e)
        {
            if (DataManager.Data.GetTotalCount() > 0)
            {
                DataManager.LoadSaveDataCompletedCallbak += new EventHandler<EventArgs>(SaveData_Completed);
                SetLoadSaveControlsVisibility(false);
                DataManager.SaveToIStorageviaSiaqodb();
            }
            else
                MessageBox.Show("No data to save", "Error", MessageBoxButton.OK);
        }

        private void LoadviaSiaqodbButton_Click(object sender, RoutedEventArgs e)
        {
            DataManager.LoadSaveDataCompletedCallbak += new EventHandler<EventArgs>(LoadData_Completed);
            if (DataManager.LoadFromIStorageviaSiaqodb())
            {
                SetLoadSaveControlsVisibility(false);
            }
            else
                MessageBox.Show("No data exist in isolated storage", "Error", MessageBoxButton.OK);
        }

        private void TestWebInvokeButton_Click(object sender, RoutedEventArgs e)
        {
            WebClient SpecialTestWebInvoke_webC = new WebClient();
            SpecialTestWebInvoke_webC.Encoding = System.Text.Encoding.UTF8;
            SpecialTestWebInvoke_webC.Headers[HttpRequestHeader.ContentType] = "application/xml; charset=utf-8";            
            string Params = "<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">Foo</string>";
            SpecialTestWebInvoke_webC.UploadStringCompleted += new UploadStringCompletedEventHandler(SpecialTestWebInvoke_UploadStringCompleted);
            SpecialTestWebInvoke_webC.UploadStringAsync(new Uri(DataManager.ODataServiceURL + "SayHello"), "POST",
                                                            Params);
        }

        void SpecialTestWebInvoke_UploadStringCompleted(object Sender, UploadStringCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                //Thread ParseThread = new Thread(SpecialTestWebInvoke_ParseThread);
                //ParseThread.Start(e.Result);
            }//if (e.Error == null)
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            
        }

        private void button1_Click_1(object sender, RoutedEventArgs e)
        {

        }//void SpecialTestWebInvoke_DownloadStringCompleted(object Sender, DownloadStringCompletedEventArgs e)

        



    }//public partial class MainPage : UserControl
    
}//namespace Ivvy_Silverlight
